package com.ta.gulimall.product.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ta.gulimall.product.view.entity.CategoryEntity;
import com.ta.gulimall.product.service.CategoryService;
import com.ta.gulimall.common.utils.system.R;



/**
 * 商品三级分类
 *
 * @author tuao
 * @email tuaoo@gmail.com
 * @date 2022-10-29 01:29:17
 */
@RestController
@RequestMapping("product/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 查询三级分类集合
     */
    @RequestMapping("/list/tree")
    public R list(){
        List<CategoryEntity> entities = categoryService.getCategorys();

        return R.ok().put("data", entities);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{catId}")
    public R info(@PathVariable("catId") Long catId){
		CategoryEntity category = categoryService.getById(catId);

        return R.ok().put("data", category);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CategoryEntity category){
		categoryService.save(category);

        return R.ok();
    }

    /**
     * 批量修改
     */
    @RequestMapping("/update/sort")
    public R update(@RequestBody List<CategoryEntity> categorys){
		categoryService.updateBatchById(categorys);

        return R.ok();
    }

    /**
     * 修改分类信息
     */
    @RequestMapping("/update")
    public R update(@RequestBody CategoryEntity category){
		categoryService.updateCategory(category);

        return R.ok();
    }

    /**
     * 删除分类集合
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody List<Long> catIds){
		categoryService.deleteCategorys(catIds);

        return R.ok();
    }

}
